package grid.celebritysocial;

import grid.celebritysocial.adapter.InfoListAdapter;
import grid.celebritysocial.adapter.InfoListItem;
import grid.celebritysocial.session.XmlData;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class ProfileActivity extends Activity  {



	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.profiletab);

		Intent intent = getIntent();
		XmlData xd = (XmlData)intent.getSerializableExtra("XMLDATA");

		ImageView pp1 = (ImageView)findViewById(R.id.pp1);
		ImageView pp2 = (ImageView)findViewById(R.id.pp2);
		ImageView pp3 = (ImageView)findViewById(R.id.pp3);
		ImageView pp4 = (ImageView)findViewById(R.id.pp4);
		ImageView pp5 = (ImageView)findViewById(R.id.pp5);

        try {
        	for(int i=0;i < (xd.photoUrl).size();i++){
            	URL url = new URL(xd.photoUrl.get(i));
            	InputStream is = url.openStream();
    	        Bitmap bm = BitmapFactory.decodeStream(is);
    	        switch (i) {
				case 0:
			        pp1.setImageBitmap(bm);
					break;
				case 1:
			        pp2.setImageBitmap(bm);
					break;
				case 2:
			        pp3.setImageBitmap(bm);
					break;
				case 3:
			        pp4.setImageBitmap(bm);
					break;
				case 4:
			        pp5.setImageBitmap(bm);
					break;
				}
        	}



		} catch (MalformedURLException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}



		//日本語名
		TextView name_ja = (TextView)findViewById(R.id.name_ja);
		if(xd.name_ja !=null && !xd.name_ja.equals("")){
			TextView name_t = (TextView)findViewById(R.id.name_t);
			name_t.setText("Name:");
			name_ja.setText(xd.name_ja);
		}

		//(kana)
		if(xd.name !=null && !xd.name.equals("")){
			String name = "("+xd.name+")";
			name_ja.setText(xd.name_ja + name);
		}

		//電話番号
		TextView tel = (TextView)findViewById(R.id.tel);
		if(xd.tel !=null && !xd.tel.equals("")){
			TextView tel_t = (TextView)findViewById(R.id.tel_t);
			tel_t.setText("TEL:");
			tel.setText(xd.tel);
		}

		//メール
		TextView mail = (TextView)findViewById(R.id.mail);
		if(xd.mail !=null && !xd.tel.equals("")){
			TextView mail_t = (TextView)findViewById(R.id.mail_t);
			mail_t.setText("Mail:");
			mail.setText(xd.mail);
		}

		//所属
		TextView belong = (TextView)findViewById(R.id.belong);
		if(xd.belong !=null && !xd.belong.equals("")){
			TextView belong_t = (TextView)findViewById(R.id.belong_t);
			belong_t.setText("Belong:");
			belong.setText(xd.belong);
		}


		List<InfoListItem> items = new ArrayList<InfoListItem>();
		items.add(new InfoListItem("aa", "List Item 001"));
		items.add(new InfoListItem("aa", "List Item 001"));
		items.add(new InfoListItem("aa", "List Item 001"));
		items.add(new InfoListItem("aa", "List Item 001"));
		items.add(new InfoListItem("aa", "List Item 001"));
		items.add(new InfoListItem("aa", "List Item 001"));
		items.add(new InfoListItem("aa", "List Item 001"));
		items.add(new InfoListItem("aa", "List Item 001"));
		items.add(new InfoListItem("aa", "List Item 001"));
		items.add(new InfoListItem("aa", "List Item 001"));
		items.add(new InfoListItem("aa", "List Item 001"));
		items.add(new InfoListItem("aa", "List Item 001"));

		InfoListAdapter adapter = new InfoListAdapter(this, R.layout.info_row, items);

		ListView list = (ListView)findViewById(R.id.listview_id);
		list.setAdapter(adapter);



	}
}